package com.hc.model.utils;

import com.hc.DTO.AccountDTO;
import com.hc.DTO.TokenDTO;
import com.hc.common.ActionEvent;
import com.hc.constants.Constants;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class AccountModel {
	public static AccountModel instance;

	public static AccountModel getInstance() {
		if (instance == null)
			instance = new AccountModel();
		return instance;
	}

	public void handleControllerEvent(ActionEvent e) {

		switch (e.action) {
		case Constants.INSERT_ACCOUNT:
			AccountDTO dto = (AccountDTO) e.viewData;
			insertContact(dto, (Context) e.sender);
			break;

		default:
			break;
		}
	}

	public boolean insertContact(AccountDTO dto, Context context) {
		boolean flag = false;
		String DATABASE_TABLE = Constants.TABLE_ACCOUNT;
		ContentValues values = new ContentValues();

		values.put("email", dto.getEmail());
		values.put("firstName", dto.getFirstName());
		values.put("lastName", dto.getLastName());
		values.put("mobileNo", dto.getMobileNo());
		values.put("password", dto.getPassword());
		DBHelper db = DBHelper.getInstance(context);
		flag = db.ExcuteInsert(null, DATABASE_TABLE, values);
		db.close();

		return flag;

	}
	
	public boolean checkAccount(Context context) {
		boolean flag = false;
		String sql = "SELECT * FROM account";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			flag = true;
			break;
		}
		c.close();
		db.close();
		return flag;
	}
}
